/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package py.com.peluq.model.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Diego_M
 */
@Entity
@Table(name = "cta_pagar", catalog = "peludb", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "CtaPagar.findAll", query = "SELECT c FROM CtaPagar c"),
    @NamedQuery(name = "CtaPagar.findByIdctaPagar", query = "SELECT c FROM CtaPagar c WHERE c.ctaPagarPK.idctaPagar = :idctaPagar"),
    @NamedQuery(name = "CtaPagar.findByIdcompraCab", query = "SELECT c FROM CtaPagar c WHERE c.ctaPagarPK.idcompraCab = :idcompraCab"),
    @NamedQuery(name = "CtaPagar.findByCompraCabFecha", query = "SELECT c FROM CtaPagar c WHERE c.ctaPagarPK.compraCabFecha = :compraCabFecha"),
    @NamedQuery(name = "CtaPagar.findByCompraCabNroFactura", query = "SELECT c FROM CtaPagar c WHERE c.ctaPagarPK.compraCabNroFactura = :compraCabNroFactura"),
    @NamedQuery(name = "CtaPagar.findByCompraCabIdproveedores", query = "SELECT c FROM CtaPagar c WHERE c.ctaPagarPK.compraCabIdproveedores = :compraCabIdproveedores")})
public class CtaPagar implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CtaPagarPK ctaPagarPK;
    @ManyToMany(mappedBy = "ctaPagarCollection")
    private Collection<OrdenPago> ordenPagoCollection;
    @JoinColumns({
        @JoinColumn(name = "idcompra_cab", referencedColumnName = "idcompra_cab", nullable = false, insertable = false, updatable = false),
        @JoinColumn(name = "compra_cab_fecha", referencedColumnName = "fecha", nullable = false, insertable = false, updatable = false),
        @JoinColumn(name = "compra_cab_nro_factura", referencedColumnName = "nro_factura", nullable = false, insertable = false, updatable = false),
        @JoinColumn(name = "compra_cab_idproveedores", referencedColumnName = "idproveedores", nullable = false, insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private CompraCab compraCab;

    public CtaPagar() {
    }

    public CtaPagar(CtaPagarPK ctaPagarPK) {
        this.ctaPagarPK = ctaPagarPK;
    }

    public CtaPagar(int idctaPagar, int idcompraCab, int compraCabFecha, int compraCabNroFactura, int compraCabIdproveedores) {
        this.ctaPagarPK = new CtaPagarPK(idctaPagar, idcompraCab, compraCabFecha, compraCabNroFactura, compraCabIdproveedores);
    }

    public CtaPagarPK getCtaPagarPK() {
        return ctaPagarPK;
    }

    public void setCtaPagarPK(CtaPagarPK ctaPagarPK) {
        this.ctaPagarPK = ctaPagarPK;
    }

    @XmlTransient
    public Collection<OrdenPago> getOrdenPagoCollection() {
        return ordenPagoCollection;
    }

    public void setOrdenPagoCollection(Collection<OrdenPago> ordenPagoCollection) {
        this.ordenPagoCollection = ordenPagoCollection;
    }

    public CompraCab getCompraCab() {
        return compraCab;
    }

    public void setCompraCab(CompraCab compraCab) {
        this.compraCab = compraCab;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (ctaPagarPK != null ? ctaPagarPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CtaPagar)) {
            return false;
        }
        CtaPagar other = (CtaPagar) object;
        if ((this.ctaPagarPK == null && other.ctaPagarPK != null) || (this.ctaPagarPK != null && !this.ctaPagarPK.equals(other.ctaPagarPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "py.com.peluq.model.entity.CtaPagar[ ctaPagarPK=" + ctaPagarPK + " ]";
    }
    
}
